/**
 * Created by leiqr on 2015/5/18.
 * 渠道营销-全民经纪人
 */
define(function (require, exports, module) {
    require("angular-ui");
    require("authorize");
    require("angular-route");
    require("permission");
    var angular = require("angular");
    require("angular-interceptor");
    require("pagination");

    angular.module('app', ['ngRoute', 'ngInterceptor', 'ngUI'])
        .config(['$routeProvider', function ($routeProvider) {
            $routeProvider
                .when('/free_broker', {templateUrl: 'inc/free_broker.html'})
                .when('/agent_broker', {templateUrl: 'inc/agent_broker.html'})
                .when('/agent_broker/:audited/:id', {templateUrl: 'inc/agent_broker.html'})
                .otherwise({redirectTo: '/free_broker'});
        }])
        .controller('MainController', ['$rootScope', '$scope', '$location', '$route', '$routeParams',
            function ($rootScope, $scope, $location, $route, $routeParams) {
                $scope.tabs = [
                    {value: '/free_broker', name: '全民经纪人'},
                    {value: '/agent_broker', name: '机构经纪人'}
                ];
                var reg = /^\/agent_broker\/(?:([^\/]+))\/(?:([^\/]+))$/;
                if (reg.test($location.path())) {
                    $scope.current = $scope.tabs[1].value;
                } else {
                    $scope.current = $location.path();
                }
                $rootScope.$on('$routeChangeSuccess', function (evt,cur,pre) {
                    if($routeParams.audited){
                        $scope.initAudited = true;
                        $scope.initAgentId = $routeParams.id;
                        $scope.current = $scope.tabs[1].value;
                        $scope.searchStatus = -2;
                    } else {
                        $scope.initAudited = false;
                        $scope.initAgentId = null;
                        $scope.searchStatus = -1;
                        $scope.current = $location.path();
                    }
                });
            }
        ]);

    angular.bootstrap(document, ['app']);
});
